import pika
from config import get_config

config = get_config()
rabbitmq_host = config.get("rabbitmq_host", "localhost")

connection = pika.BlockingConnection(pika.ConnectionParameters(host=rabbitmq_host))
channel = connection.channel()

channel.queue_declare(queue='task_queue')

# 发送任务
def send_task(message):
    channel.basic_publish(exchange='', routing_key='task_queue', body=message)
    print(f"📤 任务发送: {message}")

# 消费任务
def consume_task():
    def callback(ch, method, properties, body):
        print(f"✅ 处理任务: {body.decode()}")

    channel.basic_consume(queue='task_queue', on_message_callback=callback, auto_ack=True)
    print('👷 等待任务...')
    channel.start_consuming()
